<?php

namespace App\Kuafu\Shop\Model;

use App\Kuafu\Base\Model\BaseModel;
use App\Kuafu\Base\Model\Traits\KfSoftDeletes;
use App\Kuafu\Base\Model\Traits\KfUid;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasOne;

class ShopAttributeModel extends BaseModel
{
    use HasFactory, KfSoftDeletes, KfUid;

    protected $connection = 'mysql';
    protected $table      = 'shop_attribute';
    protected $fillable   = [
        'id',
        'categoryId',
        'name',
        'remark',
        'createdAt',
        'updatedAt',
        'createdByUid',
        'updatedByUid',
        'isDeleted',
    ];

    public function shopAttributeRel(): hasOne
    {
        return $this->hasOne(ShopAttributeCategoryModel::class, 'id', 'categoryId')->select([
            'id',
            'name',
            'type'
        ]);
    }

    public static function updateById(int $id, array $data): int
    {
        return self::query()->where('id', $id)->update($data);
    }
}
